package com.lianzhihui.minitiktok.ui.main.one

import androidx.fragment.app.Fragment
import com.bumptech.glide.Glide
import com.bytedance.tiktok.utils.NumUtils
import com.echofeng.common.ui.base.BaseActivity
import com.google.android.material.tabs.TabLayout
import com.lianzhihui.minitiktok.adapter.MyFragmentAdapter
import com.lianzhihui.minitiktok.bean.user.UserInfo
import com.lianzhihui.minitiktok.presenter.UserHomePresnterImp
import com.lianzhihui.minitiktok.view.UserHomeView
import com.lianzhihui.onlyleague.R
import kotlinx.android.synthetic.main.activity_user_center.*
import kotlinx.android.synthetic.main.personal_home_header.*
import java.util.*

class UserCenterActivity : BaseActivity() , UserHomeView,TabLayout.OnTabSelectedListener{
    private var userId: String? = null
    private lateinit var userHomePresnterImp: UserHomePresnterImp

    override fun getLayoutId(): Int {
        return R.layout.activity_user_center
    }

    override fun initView() {
        userId = intent.getStringExtra("userId")
        val fragmentList = ArrayList<Fragment>()
        fragmentList.add(UserHomeVideoFragment.newInstance(1))
        fragmentList.add(UserHomeVideoFragment.newInstance(2))
        val fragmentManager = supportFragmentManager
        val adapter = MyFragmentAdapter(fragmentManager, fragmentList)
        mViewPager.setAdapter(adapter)
        mViewPager.setScrollable(false)
        mViewPager.setOffscreenPageLimit(fragmentList.size)
        tabLayout.addOnTabSelectedListener(this)
        userHomePresnterImp = UserHomePresnterImp(context,this);
        userHomePresnterImp.getUserInfo(userId)
    }

    override fun setSuccess(o: Any?) {
    }

    override fun setFailure(o: Any?) {
    }

    override fun setMineInfoSuccess(data: UserInfo?) {
    }

    override fun setUserInfoSuccess(data: UserInfo?) {
        Glide.with(context!!).load(data!!.avatar).into(ivHead)
        tvNickname.setText(data.nick)
        tvId.setText("ID:"+data.code)
        tvAge.setText(data.years)
        tvAddress.setText(data.city)
        tvSign.setText(data.intro)
        tvGetLikeCount.setText(NumUtils.numberFilter(data.like))
        tvFocusCount.setText(NumUtils.numberFilter(data.flow))
        tvFansCount.setText(NumUtils.numberFilter(data.fans))
    }

    override fun onTabSelected(tab: TabLayout.Tab?) {
        if (tab != null) {
            mViewPager.setCurrentItem(tab.position,false)
        }
    }

    override fun onTabUnselected(tab: TabLayout.Tab?) {
    }

    override fun onTabReselected(tab: TabLayout.Tab?) {
    }
}